package com.lepai.web.controller;

import com.lepai.bean.User;
import com.lepai.component.MyFactoryBean;
import com.lepai.service.UserService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.async.DeferredResult;


/**
 * @author weihaolong
 */
@RestController
@RequestMapping("/user")
public class UserController {

    Logger logger = LogManager.getLogger();

//    @Autowired
//    private UserService userService;
    @Autowired
    private MyFactoryBean myFactoryBean;


    @PostMapping("/login")
    public User login(@RequestBody User user){
        return user;
    }

    @PostMapping(value = "/add/user")
    public DeferredResult<String> addUser(@RequestBody User user) throws Exception {
        logger.trace("添加用户对象[{}]", user);

        myFactoryBean.getObject().addUser(user);
        DeferredResult<String> dr = new DeferredResult<>();
        dr.setResult("aaaaa");
        return dr;
    }

}
